<template>
<el-container>
    <el-aside width="200px">
      <el-avatar size="medium" src="require('@/assets/pic/hushang.jpg')"></el-avatar>
      <SideMenu></SideMenu>
    </el-aside>
    <el-container>
      <el-header style="height: 55px;">
        <strong>后台管理系统</strong>
        <div class="header-avatar">
          <el-avatar size="medium" :src="userInfo.avatar">
          </el-avatar>
          <el-dropdown>
            <span class="el-dropdown-link">
              {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :underline="false" @click.native="selectUserCenter({name: 'UserCenter',title: '个人中心'})">
                <router-link to="/userCenter">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-link href="https://www.baidu.com" target="_blank">网站</el-link>
          <el-link href="https://space.bilibili.com" target="_blank">B站</el-link>
        </div>
      </el-header>
      <el-main>
        <Tabs></Tabs>
        <div style="margin: 0 15px;">
          <router-view/>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import SideMenu from './inc/SideMenu'
import Tabs from './inc/Tabs'
export default {
  name: 'Home',
  components: {
    SideMenu,
    Tabs
  },
  data () {
    return {
      userInfo: {
        id: '',
        username: '',
        avatar: ''
      }
    }
  },
  methods: {
    selectUserCenter (item) {
      this.$store.commit('addTab', item)
    },
    getUserInfo () {
      this.$axios.get('/sys-user/info').then((result) => {
        this.userInfo = result.data.data
      })
    },
    logout () {
      this.$axios.post('/logout').then((res) => {
        localStorage.clear()
        sessionStorage.clear()
        this.$store.commit('resetState')
        this.$router.push('/login')
      })
    }
  },
  created () {
    this.getUserInfo()
  }
}
</script>
<style scoped>
.el-container {
    padding: 0;
    margin: 0;
    height: 100%;
  }

  .header-avatar {
    float: right;
    width: 210px;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  .el-menu-vertical-demo {
    height: 100%;
  }

  .el-dropdown-link {
    cursor: pointer;
  }

  .el-header {
    background-color: #17B3A3;
    color: #333;
    text-align: center;
    line-height: 60px;
    padding: 0 20px;
  }

  .el-aside {
    background-color: #d3dce6;
    color: #333;
    line-height: 200px;
  }

  .el-main {
    color: #333;
    padding: 0;
  }

  a {
    text-decoration: none;
  }
</style>
